home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
tegl6b.zip
/
INTROPAK.EXE
/
lha
/
VIRTMEM.DOC
< prev
Wrap
Text File
|
1991-08-16
|
8KB
|
241 lines
{-----------------------------------------------------------------------------}
{ TEGL Windows ToolKit II }
{ Copyright (C) 1990, TEGL Systems Corporation }
{ All Rights Reserved. }
{-----------------------------------------------------------------------------}
{$I switches.inc}
{$I-}
Unit VirtMem;
INTERFACE
USES Dos, {reading and writing dos files}
Crt, {sound when accessing virtual}
errorlog;
TYPE
SegOfs = RECORD
Ofst, Segm : Word;
END;
FreeListRecPtr = ^FreeListRec;
FreeListRec = RECORD
OrgPtr : Pointer; {pointer to the start of the block}
EndPtr : Pointer; {pointer to the end of the block}
END;
{$IFNDEF NoVirt}
EMSBlockPtr = ^EMSBlock;
EMSBlock = RECORD
nextblockptr : EMSblockPtr;
Handle : Word; {Multiple handles}
EMSPage : Word; {Pages allocated}
END;
EMSFile = ^EMSFileRec;
EMSFileRec = RECORD
PageOffset : Word; {current offset within page}
BaseAddress : Word;
EMSPosition : longint;
TotalPages : Word; {Total number of 16k pages}
RootBlkPtr : EMSBlockPtr;
END;
{$ENDIF}
errorproc = Function(procnum : longint):Word;
{$IFNDEF NoVirt}
Signate = String[4];
VDskFreePtr = ^VDskFreeRecord;
VDskFreeRecord = RECORD
NextVDskFree : VDskFreePtr;
StartBlock : longint;
EndBlock : longint;
Signature : Signate;
BlockFree : Boolean;
END;
VDskBlockSizeRecord = RECORD
BSize : longint;
RealSize : longint;
Signature : signate;
BlockFree : Boolean;
Chksum : Word;
END;
VDskFile = ^VDskFileRecord;
VDskFileRecord = RECORD
VDskFreePtrChain : VDskFreePtr;
VDskTopOfFile : longint;
VDskAttribute : Word;
{ VDskPacketSave : longint;}
CASE EMSType : Boolean of
FALSE : (VDskHeapFile: File);
TRUE : (VEMSHeapFile: EMSFile);
END;
VirtualPtr = ^VirtualRec;
VirtualRec = RECORD
nxtptr : VirtualPtr;
lstptr : VirtualPtr;
MemorySize : longint;
MemoryPtr : Pointer;
MemoryLock : Boolean;
MemoryInUse : Boolean;
MemoryPageOut : Boolean;
MemoryPagePtr : longint;
VPReferBack : Pointer;
VPLastMemPtr : Pointer;
MemoryLevel : byte;
END;
CONST
{$IFDEF VSOUND}
VirtualSound : Boolean = TRUE;
{$ENDIF}
VirtualEMSHeap : VDskFile = NIL;
VirtualDSKHeap : VDskFile = NIL;
TriedEMS : Boolean = FALSE;
VirtualAnchor : Virtualptr = NIL;
MaxPageEMSOpen : Word = 25; {400k of EMS memory}
MinPageEMSAlloc: Word = 16; {256k of subsequent EMS memory}
VDskReadWrite = 1;
VDskTemporary = 2;
VDskStatus : Word = 0;
MemoryLevel : byte = 0;
{$ENDIF} {-- Novirt }
CONST
HugeMin : longint = 10000;
StandardHeapSize : longint = 10000;
CGetMemThreshold : longint = 0;
UpperHeapSize : longint = 0;
THeapOrg : Pointer = nil;
THeapPtr : Pointer = nil;
TFreePtr : Pointer = nil;
THeapTop : Pointer = nil;
TFreeMin : word = 2000;
HeapMemInit : boolean = false;
HeapChkByte : byte = $72;
ReservedByte : Pointer = nil;
MonitorRMax : longint = 1024;
MonitorRMem : longint = 5120;
MonitorRInc : longint = 16384;
HeapErrorFlag : boolean = false;
invirtual : boolean = false;
{ Virtual Error passes a word indicating where Virtual had error.
1 - MoveFromVirtual
2 - MoveToVirtual
3 - FreeVirtual
4 - CloseVirtual
}
{ VDskError passes a word indicating where Virtual Disk had error.
1 - VDskGetMem
2 - VDskFreeMem
3 - VDskReadHeapData
4 - VDskWriteHeapData
5 - VDskCloseHeapFile
6 - VDskOpenHeapFile
}
VAR VDskError : ErrorProc;
VirtualError : ErrorProc;
HugeHeapError: ErrorProc;
VirtMemError : ErrorProc;
EMS_Status : Word;
VirtMem_ExitSave : Pointer;
{-- dummy error return procedure }
Function ReturnDiskError(code:longint) : Word;
{$IFNDEF NoVirt}
Procedure SetMaxEMSSize;
Procedure UseHardDisk(yesno:Boolean);
Procedure MoveFromVirtual(DataPtr:Pointer; VirtualHeapPtr:longint);
Function MoveToVirtual(DataPtr:Pointer; HeapSize:longint) : longint;
Procedure FreeVirtual(VirtualHeapPtr:longint);
Procedure CloseVirtual;
Function VirtualMemUsed : longint;
{------EMS------}
Function EmmInstalled: Boolean;
Function EMSPagesAvailable (VAR TotalEMSPages,Pages_Available: Word): Word;
Function AllocateExpandedMemoryPages(PagesNeeded:Word; VAR Handle:Word): Word;
Function MapExpandedMemoryPages(Handle,LogicalPage,PhysicalPage: Word): Word;
Function GetPageFrameBaseAddress(VAR PageFrameAddress: Word):Word;
Function DeallocateExpandedMemoryPages (Handle: Word): Word;
Function GetVersionNumber(VAR VersionString: String): Word;
Function GetHandleCountUsed (VAR NumberOfHandles: Word): Word;
Function GetPagesOwnedByHandle (Handle: Word; VAR PagesOwned:Word): Word;
{------Virtual Disk------}
Function VDSKGetMem(VDskPacket:VDskFile; HeapSize:longint; signature:Signate) : longint;
Procedure VDSKFreeMem(VDskPacket:VDskFile; VDskHeapPtr:longint);
Procedure VDSKWriteHeapData(VDskPacket:VDskFile; DataPtr:Pointer; VDskHeapPtr:longint);
Procedure VDSKReadHeapData(VDskPacket:VDskFile; DataPtr:Pointer; VDskHeapPtr:longint);
Procedure VDskCloseHeapFile(VDskPacket:VDskFile);
Function VDskOpenHeapFile(VDskFileName : String; VDskAttribute:Word) : VDskFile;
Function VEMSOpenHeapFile : VDskFile;
Procedure VDskShowFreeList(VDskPacket:VDskFile);
{------Ems Drive------}
Function EMSOpen(MinimumPages:Word) : EMSFile;
Procedure EMSSeek(EMSRamFile:EMSFile; Position:longint);
Procedure EMSBlockWrite(EMSRamFile:EMSFile; buffer:Pointer; bytestowrite:longint);
Procedure EMSBlockRead(EMSRamFile:EMSFile; buffer:Pointer; bytestoread:longint);
Procedure EMSClose(EMSRamFile:EMSFile);
{$ENDIF} {-- NoVirt }
{------Memory --------}
Procedure InitTEGLHeap;
Function ReservedMemAvail : longint;
Function ReservedMaxAvail : longint;
Function CMaxAvail : longint;
Function CMemAvail : longint;
Procedure CGetMem(VAR Pt; Heapsize : LongInt);
Procedure FGetMem(VAR Pt; HeapSize : LongInt);
Procedure CFreeMem(VAR Pt; Heapsize : LongInt);
Procedure MoveBytes(Buffer1,Buffer2:Pointer; BytestoMove:Word);
Procedure ReserveHugeMinimum(MinimumSize : longint);
Procedure SetStandardHeapSize(Heapsize : LongInt);
{------Virtual Memory------}
Procedure VPUnLock(vp:virtualptr);
procedure VPlock(vp:virtualptr);
Function VMPageOut(memrequest:longint) : Boolean;
procedure VPUse(vp:virtualptr);
procedure VPAccess(vp:virtualptr; Var rfptr);
Procedure VPGetMem(VAR VP:virtualptr; HeapSize : LongInt);
Procedure VPFreeMem(vp:virtualptr);
Procedure VPPageOut(VP : virtualptr);
Procedure VPPageIn(vp:virtualptr);
procedure VPUnUse(vp:virtualptr);
procedure VMSetLevel(level:byte);
function VMGetLevel : byte;
procedure PushVPlevel;
procedure PopVPlevel;
procedure MonitorCheck(rmax,rmem,moremem : longint);
procedure SetMonitorThresholds(rmax,rmem,moremem : longint);
Function Linear(P : Pointer) : LongInt;
Function LinearToPointer(L : LongInt) : Pointer;
Function PtrDiff(P1, P2 : Pointer) : LongInt;
Function MemoryShuffle(size:longint): Word;
IMPLEMENTATION